package cn.cqie.frame.controller;


import cn.cqie.frame.bo.query.QueryEmpBo;
import cn.cqie.frame.entity.Emp;
import cn.cqie.frame.service.EmpService;
import cn.cqie.frame.utils.MyPageHelper;
import cn.cqie.frame.vo.EmpVo;
import cn.cqie.frame.vo.ResultVo;
import cn.cqie.frame.vo.UserVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHL
 * @since 2021-10-09
 */
@RestController
@Api("员工管理")
public class EmpController {
    @Autowired
    private EmpService empService;
    @ApiOperation("新增/更新员工信息")
    @PostMapping(value = "/emp/saveOrUpdateEmp")
    public ResultVo<EmpVo> saveOrUpdateEmp(@Valid @RequestBody Emp bo) {
        EmpVo empVo = empService.saveOrUpdateEmp(bo);
        return ResultVo.success(empVo);
    }
    @ApiOperation("查询员工信息分页")
    @GetMapping(value = "/emp/empInfoPage")
    public ResultVo<PageInfo<EmpVo>> getPageList(QueryEmpBo bo) {
        return ResultVo.success(MyPageHelper.returnPage(empService.list(bo)));
    }
    @ApiOperation("删除员工信息")
    @DeleteMapping("/emp/deleteEmp/{EmpId}")
    public ResultVo<Void> deleteEmp(@PathVariable Integer EmpId) {
        Boolean delete = empService.deleteEmp(EmpId);
        return delete ? ResultVo.success() : ResultVo.error("删除失败");
    }
    @ApiOperation("获取用户备选项")
    @GetMapping("/emp/listUsers")
    public ResultVo<List<UserVo>> listUsers(Integer empId){
        return ResultVo.success(empService.listUsers(empId));
    }

}

